home *** CD-ROM | disk | FTP | other *** search
- import java.awt.Color;
- import java.awt.Dimension;
- import java.awt.Graphics;
- import java.awt.Point;
- import java.awt.Rectangle;
- import java.awt.image.ImageObserver;
- import java.io.DataInputStream;
-
- public class CPushButtonResponse extends CDisplayResponse {
- final short IN_REGION = 256;
- final short CUSTOM_BTN = 512;
- static final byte image_on_button = 0;
- static final byte up_image = 1;
- static final byte down_image = 2;
- static final byte over_image = 3;
- static final byte image_count = 4;
- protected CFontObject m_clsFontObject = new CFontObject();
- protected int m_nFlags = 16;
- protected char m_cPrefixChar = 0;
- protected String m_strTitle = "Continue";
- protected String m_strImageOnButton = "";
- protected String m_strUpImage = "";
- protected String m_strDownImage = "";
- protected String m_strOverImage = "";
- protected String m_strCursorName = "";
- protected Color m_rgbText = null;
- protected Color m_rgbFace;
- protected Color m_rgbShadow;
- protected Color m_rgbHighlight;
- protected Color m_rgbTrans;
- protected short m_cBorderWidth;
- protected CPicture[] m_Image;
- private String m_strNewTitle;
- private int m_wState;
-
- void DrawCustomButton(Graphics var1, CRect var2) {
- if (Utils.StateTest(this.m_wState, 256)) {
- if (Utils.StateTest(this.m_wState, 8)) {
- this.m_Image[2].Draw(var1, var2);
- } else {
- this.m_Image[3].Draw(var1, var2);
- }
- } else {
- this.m_Image[1].Draw(var1, var2);
- }
- }
-
- boolean LoadFromFile(DataInputStream var1) {
- this.m_strTitle = FileLoad.ReadCString(var1);
- this.m_cPrefixChar = (char)FileLoad.ReadCPlusByte(var1);
- this.m_nFlags = FileLoad.ReadCPlusInt(var1);
- this.m_rgbText = FileLoad.ReadColor(var1);
- this.m_rgbFace = FileLoad.ReadColor(var1);
- this.m_rgbShadow = FileLoad.ReadColor(var1);
- this.m_rgbHighlight = FileLoad.ReadColor(var1);
- this.m_cBorderWidth = FileLoad.ReadCPlusByte(var1);
- if (Globals.CUR_COURSE.m_nFileVersion > 3) {
- this.m_strCursorName = FileLoad.ReadCString(var1);
- }
-
- int var2 = 0;
-
- do {
- this.m_Image[var2].LoadFromFile(var1);
- ++var2;
- } while(var2 < 4);
-
- this.m_clsFontObject.LoadFromFile(var1);
- return super.LoadFromFile(var1);
- }
-
- void Draw3DButton(Graphics var1, CRect var2) {
- Graphics var3 = var1.create();
- CRect var4 = new CRect(var2);
- ((Rectangle)var4).grow(-this.m_cBorderWidth - 1, -this.m_cBorderWidth - 1);
- if ((this.m_nFlags & 16) != 0) {
- var3.setColor(Color.black);
- var3.drawRoundRect(var2.x, var2.y, var2.width - 1, var2.height - 1, 2, 2);
- }
-
- var3.setColor(this.m_rgbFace);
- var3.fillRect(var4.x, var4.y, var4.width, var4.height);
- if (Utils.StateTest(this.m_wState, 8) && Utils.StateTest(this.m_wState, 256)) {
- for(int var6 = 0; var6 < this.m_cBorderWidth; ++var6) {
- var3.setColor(this.m_rgbShadow);
- var3.drawLine(var2.x + 1, var2.y + var6 + 1, var2.x + var2.width - 2 - var6, var2.y + var6 + 1);
- var3.drawLine(var2.x + var6 + 1, var2.y + 1, var2.x + var6 + 1, var2.y + var2.height - 3 - var6);
- var3.setColor(this.m_rgbHighlight);
- var3.drawLine(var2.x + 1 + var6, var2.y + var2.height - 2 - var6, var2.x + var2.width - 2, var2.y + var2.height - 2 - var6);
- var3.drawLine(var2.x + var2.width - 2 - var6, var2.y + 2 + var6, var2.x + var2.width - 2 - var6, var2.y + var2.height - 2);
- }
-
- int var7 = Math.min(this.m_cBorderWidth, 3);
- var4.x += var7;
- var4.y += var7;
- var4.width -= var7;
- var4.height -= var7;
- } else {
- for(int var5 = 0; var5 < this.m_cBorderWidth; ++var5) {
- var3.setColor(this.m_rgbHighlight);
- var3.drawLine(var2.x + 1, var2.y + var5 + 1, var2.x + var2.width - 2 - var5, var2.y + var5 + 1);
- var3.drawLine(var2.x + var5 + 1, var2.y + 1, var2.x + var5 + 1, var2.y + var2.height - 3 - var5);
- var3.setColor(this.m_rgbShadow);
- var3.drawLine(var2.x + 1 + var5, var2.y + var2.height - 2 - var5, var2.x + var2.width - 2, var2.y + var2.height - 2 - var5);
- var3.drawLine(var2.x + var2.width - 2 - var5, var2.y + 2 + var5, var2.x + var2.width - 2 - var5, var2.y + var2.height - 2);
- }
- }
-
- if (this.m_Image[0].m_strFilename.length() == 0) {
- var3.setColor(this.m_rgbText);
- var3.setFont(this.m_clsFontObject.GetFont());
- int var8 = Math.min(var4.height, Utils.DrawText(var3, this.m_strNewTitle, var4, 34).height);
- var4.y += (var4.height - var8) / 2;
- var4.height = var8;
- Utils.DrawText(var3, this.m_strNewTitle, var4, 2);
- } else {
- if (this.m_Image[0].m_Image != null) {
- if (this.m_Image[0].m_Image.getWidth((ImageObserver)null) < var4.width) {
- var4.x += (var4.width - this.m_Image[0].m_Image.getWidth((ImageObserver)null)) / 2;
- }
-
- if (this.m_Image[0].m_Image.getHeight((ImageObserver)null) < var4.height) {
- var4.y += (var4.height - this.m_Image[0].m_Image.getHeight((ImageObserver)null)) / 2;
- }
- }
-
- this.m_Image[0].Draw(var3, var4);
- }
- }
-
- boolean ProcessMouseUp(Point var1) {
- boolean var2 = false;
- if (Utils.StateTest(this.m_wState, 8)) {
- this.m_wState = Utils.StateClear(this.m_wState, 8);
- Globals.thePresView.Render(((CDisplayResponse)this).GetDrawRect());
- Globals.thePresView.Draw((Graphics)null, ((CDisplayResponse)this).GetDrawRect());
- var2 = true;
- }
-
- return var2;
- }
-
- boolean OnKeyPress(int var1, int var2) {
- boolean var3 = false;
- if (this.m_cPrefixChar > 0 && var1 == Character.toUpperCase(this.m_cPrefixChar)) {
- var3 = true;
- }
-
- return var3;
- }
-
- public CPushButtonResponse() {
- super(23);
- this.m_rgbFace = Color.lightGray;
- this.m_rgbShadow = Color.darkGray;
- this.m_rgbHighlight = Color.white;
- this.m_rgbTrans = null;
- this.m_cBorderWidth = 2;
- this.m_strNewTitle = "";
- this.m_wState = 0;
- this.m_Image = new CPicture[4];
-
- for(int var1 = 0; var1 < this.m_Image.length; ++var1) {
- this.m_Image[var1] = new CPicture();
- }
-
- }
-
- CResponseReturn DoResponse(int var1) {
- return super.DoResponse(var1);
- }
-
- boolean OnMouseClick(int var1, int var2, Point var3, int var4, CRect var5) {
- boolean var6 = false;
- if (var4 == 7) {
- if (var1 == 2022 && ((CDisplayResponse)this).HitTest(var3)) {
- var6 = this.ProcessMouseDown(var3);
- } else if (var1 == 2023) {
- if (((CDisplayResponse)this).HitTest(var3)) {
- var6 = this.ProcessMouseUp(var3);
- } else if (Utils.StateTest(this.m_wState, 8)) {
- this.m_wState = Utils.StateClear(this.m_wState, 8);
- }
- }
- }
-
- return var6;
- }
-
- boolean SetResponse() {
- boolean var1 = false;
- String var2 = Utils.InsertVariablesInString(this.m_strTitle);
- if (!this.m_strNewTitle.equals(var2)) {
- this.m_strNewTitle = var2;
- var1 = true;
- }
-
- CRect var3 = new CRect(((CDisplayResponse)this).GetActualRect());
- if (this.m_Image[1].m_strFilename.length() <= 0 && this.m_Image[2].m_strFilename.length() <= 0 && this.m_Image[3].m_strFilename.length() <= 0) {
- if (this.m_Image[0].m_strFilename.length() > 0) {
- if (!this.m_Image[0].HasImageLoaded()) {
- var1 = true;
- }
-
- this.m_Image[0].LoadImage();
- }
- } else {
- Dimension var5 = new Dimension();
- if (!this.m_Image[1].HasImageLoaded()) {
- var1 = true;
- }
-
- int var6 = 1;
-
- do {
- Dimension var4;
- if ((var4 = this.m_Image[var6].LoadImage()) != null) {
- var5.width = Math.max(var5.width, var4.width);
- var5.height = Math.max(var5.height, var4.height);
- }
-
- ++var6;
- } while(var6 < 4);
-
- ((Rectangle)var3).resize(Math.min(var3.width, var5.width), Math.min(var3.height, var5.height));
- this.m_wState = Utils.StateSet(this.m_wState, 512);
- }
-
- if (!((Rectangle)var3).equals(((CDisplayResponse)this).GetDrawRect())) {
- if (!((CDisplayResponse)this).GetDrawRect().isEmpty()) {
- Globals.thePresView.InvalidateOffScreenRect(((CDisplayResponse)this).GetDrawRect());
- }
-
- ((CDisplayResponse)this).SetDrawRect(var3);
- var1 = true;
- }
-
- Globals.thePresView.AddDrawObject((CIconObject)this, 1024, var1);
- return true;
- }
-
- boolean ProcessMouseDown(Point var1) {
- if (!Utils.StateTest(this.m_wState, 8)) {
- this.m_wState = Utils.StateSet(this.m_wState, 8);
- Globals.thePresView.Render(((CDisplayResponse)this).GetDrawRect());
- Globals.thePresView.Draw((Graphics)null, ((CDisplayResponse)this).GetDrawRect());
- }
-
- return false;
- }
-
- boolean OnMouseMove(int var1, Point var2, int var3, CRect var4) {
- if (var3 == 7) {
- CRect var5 = new CRect();
- if (var4 != null) {
- var5.reshape(var4);
- } else {
- var5.reshape(((CDisplayResponse)this).GetActualRect());
- }
-
- if (((CDisplayResponse)this).HitTest(var2)) {
- if (!Utils.StateTest(this.m_wState, 256)) {
- this.m_wState = Utils.StateSet(this.m_wState, 256);
- if (Utils.StateTest(this.m_wState, 512) || Utils.StateTest(this.m_wState, 8)) {
- Globals.thePresView.Render(var5);
- Globals.thePresView.Draw((Graphics)null, var5);
- }
-
- if ((((CResponse)this).GetResponseFlags() & 32) == 0 && super.m_ActionManager.GetIconList().size() > 0) {
- super.m_ActionManager.OnDoAction();
- Globals.thePresView.RenderAndDrawDirtyList();
- }
- }
- } else if (Utils.StateTest(this.m_wState, 256)) {
- this.m_wState = Utils.StateClear(this.m_wState, 256);
- if (Utils.StateTest(this.m_wState, 512) || Utils.StateTest(this.m_wState, 8)) {
- Globals.thePresView.Render(var5);
- Globals.thePresView.Draw((Graphics)null, var5);
- }
-
- if ((((CResponse)this).GetResponseFlags() & 32) == 0 && super.m_ActionManager.GetIconList().size() > 0) {
- super.m_ActionManager.RemoveDrawObjects();
- Globals.thePresView.RenderAndDrawDirtyList();
- }
- }
- }
-
- return false;
- }
-
- void DrawObject(Graphics var1, int var2, CRect var3) {
- if (Utils.StateTest(this.m_wState, 512)) {
- this.DrawCustomButton(var1, var3);
- } else {
- this.Draw3DButton(var1, var3);
- }
- }
- }
-